package com.beehoo.dcportal.action;

import com.beehoo.dcportal.common.base.BaseAction;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.LeaderBean;
import com.beehoo.dcportal.model.MenuBean;
import com.beehoo.dcportal.model.MessageBean;
import com.beehoo.dcportal.model.RelatedLinkBean;
import com.beehoo.dcportal.service.ICommonServ;
import com.beehoo.dcportal.service.ILeaderServ;
import com.beehoo.dcportal.service.IMessageServ;
import com.beehoo.dcportal.service.IRelatedLinkServ;
import java.io.PrintStream;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PortletAction extends BaseAction
{
  private static final long serialVersionUID = 6430098990976668754L;
  private IMessageServ msgServ;
  private ILeaderServ leaderServ;
  private IRelatedLinkServ relatedLinkServ;
  private int rows;
  private String msgType;
  private List<MessageBean> txtMsgList;
  private List<MessageBean> picMsgList;
  private List<RelatedLinkBean> linkList;
  private List<LeaderBean> leaderList;
  private List<MenuBean> lcoIntroList;
  private MessageBean txtMsg;

  public List<MenuBean> getLcoIntroList()
  {
    return this.lcoIntroList;
  }

  public void setLcoIntroList(List<MenuBean> lcoIntroList) {
    this.lcoIntroList = lcoIntroList;
  }

  public List<LeaderBean> getLeaderList() {
    return this.leaderList;
  }

  public void setLeaderList(List<LeaderBean> leaderList) {
    this.leaderList = leaderList;
  }

  public String getMsgType() {
    return this.msgType;
  }

  public void setMsgType(String msgType) {
    this.msgType = msgType;
  }

  public List<MessageBean> getTxtMsgList() {
    return this.txtMsgList;
  }

  public void setTxtMsgList(List<MessageBean> txtMsgList) {
    this.txtMsgList = txtMsgList;
  }

  public List<MessageBean> getPicMsgList() {
    return this.picMsgList;
  }

  public void setPicMsgList(List<MessageBean> picMsgList) {
    this.picMsgList = picMsgList;
  }

  public List<RelatedLinkBean> getLinkList() {
    return this.linkList;
  }

  public void setLinkList(List<RelatedLinkBean> linkList) {
    this.linkList = linkList;
  }

  public IMessageServ getMsgServ() {
    return this.msgServ;
  }

  public void setMsgServ(IMessageServ msgServ) {
    this.msgServ = msgServ;
  }

  public ILeaderServ getLeaderServ() {
    return this.leaderServ;
  }

  public void setLeaderServ(ILeaderServ leaderServ) {
    this.leaderServ = leaderServ;
  }

  public void setRelatedLinkServ(IRelatedLinkServ relatedLinkServ) {
    this.relatedLinkServ = relatedLinkServ;
  }

  public MessageBean getTxtMsg()
  {
    return this.txtMsg;
  }

  public void setTxtMsg(MessageBean txtMsg)
  {
    this.txtMsg = txtMsg;
  }

  public String picNews()
  {
    try {
      this.rows = Integer.parseInt((String)this.paramMap.get("rows"));
    } catch (Exception e) {
      this.rows = 8;
    }
    this.msgType = ((String)this.paramMap.get("msgType"));
    try
    {
      this.picMsgList = this.msgServ.getPicMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
    } catch (BaseException e) {
      return "error";
    }

    return "success";
  }

  public String textNews()
  {
    try {
      this.rows = Integer.parseInt((String)this.paramMap.get("rows"));
    } catch (Exception e) {
      this.rows = 8;
    }
    this.msgType = ((String)this.paramMap.get("msgType"));
    try
    {
      this.txtMsgList = this.msgServ.getTextMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
    } catch (BaseException e) {
      return "error";
    }

    return "success";
  }

  public String ptNews()
  {
    try {
      this.rows = Integer.parseInt((String)this.paramMap.get("rows"));
    } catch (Exception e) {
      this.rows = 8;
    }
    this.msgType = ((String)this.paramMap.get("msgType"));
    try
    {
      this.txtMsgList = this.msgServ.getPortletTextMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
      this.picMsgList = this.msgServ.getPicMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
    } catch (BaseException e) {
      return "error";
    }

    return "success";
  }

  public String spNews()
  {
    try {
      this.rows = Integer.parseInt((String)this.paramMap.get("rows"));
    } catch (Exception e) {
      this.rows = 8;
    }
    this.msgType = ((String)this.paramMap.get("msgType"));
    try
    {
      this.txtMsgList = this.msgServ.getMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
    } catch (BaseException e) {
      return "error";
    }

    return "success";
  }

  public String leaderIntro() {
    try {
      this.leaderList = this.leaderServ.getLeaderList((String)this.paramMap.get("streetId"));
    } catch (BaseException e) {
      return "error";
    }
    return "success";
  }

  public String lcoIntro()
  {
    try {
      this.lcoIntroList = getCommServ().querySpecialMenu((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"));
    } catch (BaseException e) {
      return "error";
    }
    return "success";
  }

  public String relatedLink()
  {
    try {
      this.linkList = this.relatedLinkServ.getRelatedLinkList((String)this.paramMap.get("streetId"));
    } catch (BaseException e) {
      return "error";
    }
    return "success";
  }

  public String ftNews()
  {
    try {
      this.rows = Integer.parseInt((String)this.paramMap.get("rows"));
    } catch (Exception e) {
      this.rows = 8;
    }
    this.msgType = ((String)this.paramMap.get("msgType"));
    try
    {
      this.txtMsgList = this.msgServ.getTextMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
      this.txtMsg = this.msgServ.getMessageItem((String)this.paramMap.get("streetId"), ((MessageBean)this.txtMsgList.get(0)).getMsgId());
      String show = this.txtMsg.getMsgContent();
      show = show.replaceAll("<[.[^<]]*>", "");
      show = show.replaceAll("&nbsp;", "");
      this.txtMsg.setMsgContent(show);
      this.picMsgList = this.msgServ.getPicMessageList((String)this.paramMap.get("streetId"), (String)this.paramMap.get("msgType"), this.rows);
    } catch (BaseException e) {
      return "error";
    }

    return "success";
  }

  public String Html2Text(String inputString) {
    String htmlStr = inputString;
    String textStr = "";
    try
    {
      String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
      String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
      String regEx_html = "<[^>]+>";

      Pattern p_script = Pattern.compile(regEx_script, 2);
      Matcher m_script = p_script.matcher(htmlStr);
      htmlStr = m_script.replaceAll("");

      Pattern p_style = Pattern.compile(regEx_style, 2);
      Matcher m_style = p_style.matcher(htmlStr);
      htmlStr = m_style.replaceAll("");

      Pattern p_html = Pattern.compile(regEx_html, 2);
      Matcher m_html = p_html.matcher(htmlStr);
      htmlStr = m_html.replaceAll("");

      textStr = htmlStr;
    }
    catch (Exception e) {
      System.err.println("Html2Text: " + e.getMessage());
    }

    return textStr;
  }
}